#include <bits/stdc++.h>
#define int long long
using namespace std;
bool color[100005];
int a[100005];
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        int n=0,ans=-1;
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        for(int x=0;x<(1<<(n));x++){
            //cout<<"x="<<x;
            int cnt=0;
            memset(color,false,sizeof color);
            for(int i=1;i<=n;i++){
                if(x>>(i-1) bitand 1){
                    //cout<<","<<i;
                    color[i]=true;
                }
            }
            for(int i=1;i<=n;i++){
                for(int j=i-1;j>0;j--){
                    if(color[j]==color[i]){
                        cnt+=(a[i]==a[j]?a[i]:0);
                        break;
                    }
                }
            }
            //cout<<",cnt="<<cnt;
            ans=max(ans,cnt);
            //cout<<",ans="<<ans<<endl;
        }
        cout<<ans<<endl;
    }
    return 0;
}
